home *** CD-ROM | disk | FTP | other *** search
Text File | 2001-02-20 | 2.8 KB | 116 lines | [AMAS/AMAP] |
- // -* CameraRotateBehavior.js *-
- //
- // Name: CameraRotate behavior
- // Description:
- // Author:
- // Version: $Id: CameraRotateBehavior.js,v 1.6 2000/12/21 15:03:30 consumer Exp $
- //
-
- //
- // Private variables
- //
-
- var phiLimit = 0.9 * Math.PI / 2;
- var phiMin = 20;
- var phiMax = 80;
-
- //
- // Private functions
- //
-
- var rotateCameras = new Array(1);
-
- function CameraRotateBehavior(camera, intensity)
- {
- // Member methods of the behavior
- this.start = CameraRotateBehaviorStart;
- this.stop = CameraRotateBehaviorStop;
-
- this.camera = camera;
- this.intensity = intensity;
- this.dragID = TSMakeUniqID("DragForce_" + camera);
-
- TSMakeDragForce(this.dragID, intensity, '0 0 0',
- TSMakeStringFromPoint(TSSolidGetPosition(camera)));
-
- this.dampingID = TSMakeUniqID("DampingForce_" + camera);
- TSMakeDampingSolidForce(this.dampingID, "1.0", "1.0");
-
- TSAppendChild(camera, this.dragID);
- TSAppendChild(camera, this.dampingID);
-
- TSUpdateNode(camera);
-
- // Free the camera
- TSUpdateNodeAttribute(camera, 'fixed', '0');
- }
-
- function CameraRotateBehaviorStart(direction, step)
- {
- // Get the position of the camera dragger solid
- var camPosition = TSCameraGetPosition(this.camera);
- // Get the dragger target point
- var tgtPosition = TSCameraGetTargetPosition(this.camera);
-
- // Create the vector between the camera and the target point ( in spherical coordinates )
- var sphericCoords = TSVectorToSphericCoords(TSMakeVector(tgtPosition, camPosition));
-
- // Compute the current rotation angles
- switch (direction)
- {
- case "right":
- sphericCoords.theta += TSDegToRad(step);
- break;
-
- case "left":
- sphericCoords.theta -= TSDegToRad(step);
- break;
-
- case "up":
- newPhi = sphericCoords.phi + TSDegToRad(step);
- if (newPhi < phiLimit && newPhi < TSDegToRad(phiMax)) {
- sphericCoords.phi = newPhi;
- }
- break;
-
- case "down":
- newPhi = sphericCoords.phi - TSDegToRad(step);
- if (newPhi > -phiLimit && newPhi > TSDegToRad(phiMin)) {
- sphericCoords.phi = newPhi;
- }
- break;
- }
-
- var position = TSSphericCoordsToVector(sphericCoords);
- position = TSPointTranslate(position, tgtPosition.x, tgtPosition.y, tgtPosition.z);
-
- // Move the camera dragger at the new location
- TSUpdateNodeAttribute(this.dragID, "targetPoint", TSMakeStringFromPoint(position));
- }
-
- function CameraRotateBehaviorStop(camera)
- {
- }
-
- //
- // Event functions (public)
- //
-
- function CameraRotateBehaviorStartEvent(obj, event)
- {
- var camera = TSGetExtraParam(event, 'camera');
- var speed = TSGetExtraParam(event, 'speed');
- var direction = TSGetExtraParam(event, 'direction');
- var step = TSGetExtraParam(event, 'step');
-
- if (rotateCameras[camera] == null) {
- rotateCameras[camera] = new CameraRotateBehavior(camera, parseFloat(speed) * 10);
- }
-
- rotateCameras[camera].start(direction, step);
- }
-
- function CameraRotateBehaviorStopEvent(obj, event)
- {
- }
-